package com.example.multiactivity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import android.widget.Button
import android.widget.EditText

class ThirdActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_third)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val confirmButton = findViewById<Button>(R.id.thirdButton);
        var thirdEditText = findViewById<EditText>(R.id.thirdEditText);

        confirmButton.setOnClickListener {
            // 传递数据给 main activity
            val resultIntent = Intent()
            resultIntent.putExtra("resultKey", thirdEditText.text.toString())
            setResult(Activity.RESULT_OK, resultIntent)
            finish(); // 直接返回数据
        }
    }
}